﻿using Baik.Interface.Execution;
using Baik.Interface.Expression;
using Baik.Interface.Framework;

namespace Baik.Expression
{
    public class Reference : Expression , IReference
    {
        public Reference(IInjector inject) : base(inject)
        {
            
        }
        
        public override IObject Evaluate()
        {
            var rtn = EvaluationScope;
            if (Host != null) rtn = Host.Evaluate(rtn);
            return rtn.Get(Name);
        }

        public string AsString()
        {
            return Host == null ?  "" : Host.AsString() +  Name;
        }        
        public IExpression Host { get; set; }
        public string Name { get; set; }
    }
}